package com.wzxy.wzinfo.config;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import com.wzxy.wzinfo.entiry.User;


public class SimpleLoginSuccessHandler implements AuthenticationSuccessHandler,InitializingBean {

	@Override
	public void afterPropertiesSet() throws Exception {
		
	}

	@Override
	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		
		UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext()
			    .getAuthentication()
			    .getPrincipal();
		User user = new User();
		System.out.println(userDetails.getUsername());
		user.setUsername(userDetails.getUsername());
		request.getSession().setAttribute("user", user);
		request.getRequestDispatcher("User/login").forward(request, response);
	}
	
	

}
